<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>

    <script>

        console.log(localStorage);



        // setItem(名称,内容)  设置 / 修改
        // getItem(名称)   返回名称对应的内容    null


        // clear()   清除所有的数据


        // key(i)   接受下标   ，  对象本身无序  一般在遍历的时候使用    

        // localStorage 不适合用for in  遍历

        // for   length   



        // 存储数据
        localStorage.setItem('yy', '123');
        localStorage.setItem('cc', '345');


        // console.log(localStorage.getItem('qq'));


        // localStorage.removeItem('yy');

        // localStorage.setItem('cc', '666');


        // localStorage.clear();


        // console.log(localStorage.key(1)) ;

        // localStorage 是一个对象
        // for (var key in localStorage) {
        //     console.log(key);   // 所有的属性和方法都被遍历了
        // }


        for (var i = 0; i < localStorage.length; i++) {
            console.log(localStorage.key(i));
            let key = localStorage.key(i);
            console.log(localStorage.getItem(key));
        }


    </script>

</body>

</html>